package com.zzy.face.dao;

import com.zzy.face.dto.TeacherInfo;
import com.zzy.face.dto.TeacherList;
import com.zzy.face.model.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author 朱泽玉
 * @Create 2022/1/29 11:05
 * @Description
 * @Modified By:
 */
@Repository
public interface TeacherDao extends JpaRepository<Teacher,Long>, JpaSpecificationExecutor<Teacher> {
    //    Student findStudentByMobile(String mobile);
    @Query("SELECT new com.zzy.face.dto.TeacherInfo(a.uid,a.Identity,a.birthday,a.college,a.date_time,a.idNumber,a.mobile,a.name,a.sex,a.state) from Account as a left join Teacher as t on a.uid = t.uid where t.uid is not null ")
    List<TeacherInfo> findTeachersInfo();

    @Query("SELECT new com.zzy.face.dto.TeacherInfo(a.uid,a.Identity,a.birthday,a.college,a.date_time,a.idNumber,a.mobile,a.name,a.sex,a.state) from Account as a left join Teacher as t on a.uid = t.uid and a.uid = ?1 where t.uid is not null ")
    TeacherInfo findTeacherInfo(Long uid);

    @Query("SELECT new com.zzy.face.dto.TeacherList(a.uid,a.name,a.mobile) from Account as a where a.state = 2 and a.Identity=1 and a.college=?1")
    List<TeacherList> findTeacherListInCollege(String college);
}
